home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ex / checkdisk1.c < prev    next >
C/C++ Source or Header  |  1987-02-16  |  2KB  |  86 lines

  1. /* checkdisk.c */
  2.  
  3. #include "devices/trackdisk.h"
  4.  
  5. #define BLOCKSIZE TD_SECTOR
  6. #define MEMF_CHIP (1L<<1)
  7.  
  8. unsigned char *diskbuffer;
  9. long td_open_error = -1;
  10.  
  11. struct MsgPort *diskport;
  12. struct IOExtTD *diskreq;
  13.  
  14. extern struct MsgPort *CreatePort();
  15. extern struct IORequest *CreateExtIO();
  16.  
  17. void MotorOnOff(onoff)    /* TURN DISK MOTOR ON/OFF */
  18. long onoff;
  19. {
  20.  diskreq->iotd_Req.io_Length = onoff;
  21.  diskreq->iotd_Req.io_Command = TD_MOTOR;
  22.  DoIO(diskreq);
  23. }
  24.  
  25.  
  26. main(argc,argv)
  27. int argc;
  28. char *argv[];
  29. {
  30. long unit, offset;
  31.  
  32. if (argc>1)
  33. {
  34.  unit = atoi(argv[1]);
  35.  if( unit < 0 || unit > 3) exit(0);
  36. }
  37. else
  38.  unit = 1;
  39.  
  40. if((diskbuffer = AllocMem(BLOCKSIZE,MEMF_CHIP))==0) cleanup();
  41.     
  42. if((diskport = CreatePort(0,0)) == 0) cleanup();
  43. /* make an io request block for communicating with the disk */
  44. if((diskreq = (struct IOExtTD *)CreateExtIO(diskport, sizeof(struct IOExtTD)))== 0)
  45.     cleanup();    
  46.  
  47. if(td_open_error = OpenDevice(TD_NAME,unit,diskreq,0)) cleanup();
  48.  
  49. MotorOnOff(1); /* Motor On */
  50.  
  51. for(offset=(NUMSECS*NUMCYLS*NUMHEADS-1)*BLOCKSIZE;offset>=0;offset-=BLOCKSIZE)    
  52. {
  53.    diskreq->iotd_Req.io_Flags = 0;      
  54.    diskreq->iotd_Req.io_Length = BLOCKSIZE;      
  55.    diskreq->iotd_Req.io_Data = (APTR)diskbuffer;    
  56.    diskreq->iotd_Req.io_Offset = offset; /* type long */
  57.    diskreq->iotd_Req.io_Command = ETD_READ;
  58.         /* check that disk not changed before reading */
  59.    diskreq->iotd_Count = 0xFFFFFFFF;
  60.    diskreq->iotd_SecLabel = 0;        
  61.     
  62.    DoIO(diskreq);
  63.  
  64.    if(diskreq->iotd_Req.io_Error != 0) 
  65.    printf("\nError %ld at Cylinder %ld, Sector %ld, Head %ld.",
  66.     diskreq->iotd_Req.io_Error,
  67.         offset/(NUMSECS*NUMHEADS*BLOCKSIZE),
  68.         offset/(NUMCYLS*NUMHEADS*BLOCKSIZE),
  69.         offset/(NUMCYLS*NUMSECS*BLOCKSIZE)
  70.         );
  71. }
  72. MotorOnOff(0);
  73.  
  74. cleanup();
  75. }    /* end of main */
  76.  
  77. cleanup()
  78. {
  79. if(diskbuffer) FreeMem(diskbuffer,BLOCKSIZE);
  80. if(!td_open_error) CloseDevice(diskreq);
  81. if(diskreq) DeleteExtIO(diskreq, sizeof(struct IOExtTD));
  82. if(diskport) DeletePort(diskport);
  83. exit(0);
  84. }
  85.  
  86.